
package cn.edu.scau.cmi.hombio.dao;

import cn.edu.scau.cmi.hombio.domain.PreventionType;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage PreventionType entities.
 * 
 */
@Repository("PreventionTypeDAO")

@Transactional
public class PreventionTypeDAOImpl extends AbstractJpaDao<PreventionType> implements PreventionTypeDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
			PreventionType.class }));

	/**
	 * EntityManager injected by Spring for persistence unit pig
	 *
	 */
	@PersistenceContext(unitName = "pig")
	private EntityManager entityManager;

	/**
	 * Instantiates a new PreventionTypeDAOImpl
	 *
	 */
	public PreventionTypeDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findPreventionTypeByMemo
	 *
	 */
	@Transactional
	public Set<PreventionType> findPreventionTypeByMemo(String memo) throws DataAccessException {

		return findPreventionTypeByMemo(memo, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByMemo
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findPreventionTypeByMemo(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPreventionTypeByMemo", startResult, maxRows, memo);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findPreventionTypeByReportQuality
	 *
	 */
	@Transactional
	public Set<PreventionType> findPreventionTypeByReportQuality(Integer reportQuality) throws DataAccessException {

		return findPreventionTypeByReportQuality(reportQuality, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByReportQuality
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findPreventionTypeByReportQuality(Integer reportQuality, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPreventionTypeByReportQuality", startResult, maxRows, reportQuality);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findPreventionTypeById
	 *
	 */
	@Transactional
	public PreventionType findPreventionTypeById(Integer id) throws DataAccessException {

		return findPreventionTypeById(id, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeById
	 *
	 */

	@Transactional
	public PreventionType findPreventionTypeById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findPreventionTypeById", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.PreventionType) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findPreventionTypeByName
	 *
	 */
	@Transactional
	public Set<PreventionType> findPreventionTypeByName(String name) throws DataAccessException {

		return findPreventionTypeByName(name, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findPreventionTypeByName(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPreventionTypeByName", startResult, maxRows, name);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findPreventionTypeByQuality
	 *
	 */
	@Transactional
	public Set<PreventionType> findPreventionTypeByQuality(java.math.BigDecimal quality) throws DataAccessException {

		return findPreventionTypeByQuality(quality, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByQuality
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findPreventionTypeByQuality(java.math.BigDecimal quality, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPreventionTypeByQuality", startResult, maxRows, quality);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findPreventionTypeByMemoContaining
	 *
	 */
	@Transactional
	public Set<PreventionType> findPreventionTypeByMemoContaining(String memo) throws DataAccessException {

		return findPreventionTypeByMemoContaining(memo, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByMemoContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findPreventionTypeByMemoContaining(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPreventionTypeByMemoContaining", startResult, maxRows, memo);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findPreventionTypeByNameContaining
	 *
	 */
	@Transactional
	public Set<PreventionType> findPreventionTypeByNameContaining(String name) throws DataAccessException {

		return findPreventionTypeByNameContaining(name, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findPreventionTypeByNameContaining(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPreventionTypeByNameContaining", startResult, maxRows, name);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllPreventionTypes
	 *
	 */
	@Transactional
	public Set<PreventionType> findAllPreventionTypes() throws DataAccessException {

		return findAllPreventionTypes(-1, -1);
	}

	/**
	 * JPQL Query - findAllPreventionTypes
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<PreventionType> findAllPreventionTypes(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllPreventionTypes", startResult, maxRows);
		return new LinkedHashSet<PreventionType>(query.getResultList());
	}

	/**
	 * JPQL Query - findPreventionTypeByPrimaryKey
	 *
	 */
	@Transactional
	public PreventionType findPreventionTypeByPrimaryKey(Integer id) throws DataAccessException {

		return findPreventionTypeByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findPreventionTypeByPrimaryKey
	 *
	 */

	@Transactional
	public PreventionType findPreventionTypeByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findPreventionTypeByPrimaryKey", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.PreventionType) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(PreventionType entity) {
		return true;
	}
}
